﻿
using CommonServiceLocator;
using MS.Common.Helpers;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading;
using wpf.Triage.DataModel;
using Wpf.Models;

namespace wpf.Triage
{
    public class TriageService
    {
       
        #region 属性
        /// <summary>
        /// 延迟加载对象  2022-03-28
        /// </summary>
        private static readonly Lazy<TriageService> _lazy =
            new Lazy<TriageService>(() => new TriageService(), LazyThreadSafetyMode.PublicationOnly);

        /// <summary>
        /// 单例对象  2022-03-28
        /// </summary>
        public static TriageService Instance => _lazy.Value;
        /// <summary>
        /// 接口工具服务接口   2022-03-28
        /// </summary>
        private readonly InterfaceToolHelper jsService;

        /// <summary>
        /// 接口工具    2022-01-27
        /// </summary>
        private readonly IRestClient client;
        #endregion

        #region 构造方法
        /// <summary>
        /// 构造方法   2022-03-28
        /// </summary>
        private TriageService()
        {
            jsService = InterfaceToolHelper.Instance;
            client = ServiceLocator.Current.GetInstance<IRestClient>();
        }
        #endregion

        #region 分诊界面方法

        /// <summary>
        /// 病人列表，获取所有病人
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<Tr_PatientVisitInfo> GetPatientVisitInfoByBULKINJURYID(string id)
        {
            var result = new ObservableCollection<Tr_PatientVisitInfo>();
            try
            {
                var request = new RestRequest("api/Triage/GetPatientVisitInfoByBULKINJURYID", Method.GET);
                request.AddParameter("id", id); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<ObservableCollection<Tr_PatientVisitInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 病人列表，获取所有病人
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<Tr_PatientVisitInfo> GetPatientVisitInfo()
        {
            var result = new ObservableCollection<Tr_PatientVisitInfo>();
            try
            {
                var request = new RestRequest("api/Triage/GetPatientVisitInfo", Method.GET);
                //request.AddParameter("pvid", pvid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<ObservableCollection<Tr_PatientVisitInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        public Tr_PatientVisitInfo GetPatientVisitInfoByPvid(string pvid)
        {
            var result = new Tr_PatientVisitInfo();
            try
            {
                var request = new RestRequest("api/Triage/GetPatientVisitInfoByPvid", Method.GET);
                request.AddParameter("pvid", pvid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Tr_PatientVisitInfo>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        public Tr_PatientVisitInfo GetPatientVisitInfoByPatientId(string PatientId)
        {
            var result = new Tr_PatientVisitInfo();
            try
            {
                var request = new RestRequest("api/Triage/GetPatientVisitInfoByPatientId", Method.GET);
                request.AddParameter("PatientId", PatientId); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Tr_PatientVisitInfo>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 查询在科视图，判断是否在科
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public List<PatientInfo> GetViewPatientVisitInfoByPatientId(string patientid)
        {
            var result = new List<PatientInfo>();
            try
            {
                var request = new RestRequest("api/PatientInfo/GetPatientInfoByPatientId", Method.GET);
                request.AddParameter("patientid", patientid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<List<PatientInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 病人列表，获取所有病人
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<Tr_PatientVisitInfo> GetPatientVisitInfoByDate(DateTime stratdate, DateTime enddate, string hospitalCode)
        {
            var result = new ObservableCollection<Tr_PatientVisitInfo>();
            try
            {
                var request = new RestRequest("api/Triage/GetPatientVisitInfoByDate", Method.GET);
                request.AddParameter("strat", stratdate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                request.AddParameter("end", enddate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                request.AddParameter("hospitalCode", hospitalCode);
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<ObservableCollection<Tr_PatientVisitInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 病人列表，获取所有病人
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<Tr_PatientVisitInfo> GetPatWaringListByDate()
        {
            var result = new ObservableCollection<Tr_PatientVisitInfo>();
            try
            {
                var request = new RestRequest("api/Triage/GetPatWaringListByDate", Method.GET);
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<ObservableCollection<Tr_PatientVisitInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 通过患者id,获取数据库最新的体征数据
        /// </summary>
        /// <param name="pvid"></param>
        /// <returns></returns>
        public Tr_VitalsignRecordInfo GetVitalsignRecordByTid(string tid)
        {
            var result = new Tr_VitalsignRecordInfo();
            try
            {
                var request = new RestRequest("api/Triage/GetVitalsignRecordByTid", Method.GET);
                request.AddParameter("tid", tid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Tr_VitalsignRecordInfo>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 获取时间段内最新体征数据
        /// </summary>
        /// <param name="strat"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public List<Tr_VitalsignRecordInfo> GetVitalsignRecordByDate(DateTime stratdate, DateTime enddate)
        {
            var result = new List<Tr_VitalsignRecordInfo>();
            try
            {
                var request = new RestRequest("api/Triage/GetVitalsignRecordByDate", Method.GET);
                request.AddParameter("strat", stratdate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                request.AddParameter("end", enddate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<List<Tr_VitalsignRecordInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 获取时间段内的评分数据
        /// </summary>
        /// <param name="stratdate"></param>
        /// <param name="enddate"></param>
        /// <returns></returns>
        public List<Triage_PatientScore> GetTriageScoreByByDate(DateTime stratdate, DateTime enddate)
        {
            var result = new List<Triage_PatientScore>();
            try
            {
                var request = new RestRequest("api/Triage/GetTriageScoreByByDate", Method.GET);
                request.AddParameter("strat", stratdate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                request.AddParameter("end", enddate.ToString("yyy-MM-dd HH:mm")); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<List<Triage_PatientScore>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 通过群伤编号,获取群伤数据
        /// </summary>
        /// <param name="pvid"></param>
        /// <returns></returns>
        public Tr_GroupInjuryInfo GetGroupInjuryInfoById(string Id)
        {
            var result = new Tr_GroupInjuryInfo();
            try
            {
                var request = new RestRequest("api/Triage/GetGroupInjuryInfoById", Method.GET);
                request.AddParameter("Id", Id); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Tr_GroupInjuryInfo>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 通过患者id获取评分结果
        /// </summary>
        /// <param name="pvid"></param>
        /// <returns></returns>
        public Triage_PatientScore GetTriage_ScoreByPvid(string pvid)
        {
            var result = new Triage_PatientScore();
            try
            {
                var request = new RestRequest("api/Triage/GetTriage_ScoreByPvid", Method.GET);
                request.AddParameter("pvid", pvid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Triage_PatientScore>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 通过群伤编号,获取群伤数据
        /// </summary>
        /// <param name="pvid"></param>
        /// <returns></returns>
        public ObservableCollection<Tr_GroupInjuryInfo> SerchGroupInjuryInfo(string stratdate, string enddate)
        {
            var result = new ObservableCollection<Tr_GroupInjuryInfo>();
            try
            {
                var request = new RestRequest("api/Triage/SerchGroupInjuryInfo", Method.GET);
                request.AddParameter("strat", stratdate);
                request.AddParameter("end", enddate);
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<ObservableCollection<Tr_GroupInjuryInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
 
        /// <summary>
        /// 通过病人id获取分诊记录
        /// </summary>
        /// <param name="pvid"></param>
        /// <returns></returns>
        public Tr_TriageRecord GetTriageRecordByPvid(string pvid)
        {
            var result = new Tr_TriageRecord();
            try
            {
                var request = new RestRequest("api/Triage/GetTriageRecordByPvid", Method.GET);
                request.AddParameter("pvid", pvid); // replaces matching token in request.Resource
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<Tr_TriageRecord>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 添加基本信息
        /// </summary>
        /// <param name="PatientVisitInfo"></param>
        /// <returns></returns>
        public ResponseApi<CommonResult> TriageSaveInfo(Tr_PatientVisitInfo PatientVisitInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/AddPatientVisitInfo", Method.POST);
                var json = JsonConvert.SerializeObject(PatientVisitInfo);
                request.AddJsonBody(json);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 基本与分诊信息保存
        /// </summary>
        /// <param name="PatientVisitInfo"></param>
        /// <returns></returns>
        public ResponseApi<CommonResult> SaveTriagePatientAndTriageRecordSave(Tr_PatientVisitInfo patientVisitInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/SaveTriagePatientAndTriageRecordSave", Method.POST);
                var json1 = JsonConvert.SerializeObject(patientVisitInfo);
                request.AddJsonBody(json1);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 更新院前号
        /// </summary>
        /// <param name="PatientVisitInfo"></param>
        /// <returns></returns>
        public ResponseApi<CommonResult> UpdPatientYQHM(Tr_PatientVisitInfo patientVisitInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/UpdPatientYQHM", Method.POST);
                var json1 = JsonConvert.SerializeObject(patientVisitInfo);
                request.AddJsonBody(json1);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }

        /// <summary>
        /// 添加体恒数据
        /// </summary>
        /// <param name="PatientVisitInfo"></param>
        /// <returns></returns>
        public ResponseApi<CommonResult> AddVitalsignRecord(Tr_VitalsignRecordInfo vitalsignRecordInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/AddVitalsignRecord", Method.POST);
                var json = JsonConvert.SerializeObject(vitalsignRecordInfo);
                request.AddJsonBody(json);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        #endregion

        public CommonResult GetHisPatInfo(CardInfo pat)
        {
            

            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("GetPatInfo");
            if (GetPatInfo == null)
            {
                result.Result = false;
                result.ErrMsg = "请配置获取患者信息的接口方法【GetPatInfo】";
                return result;
            }
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                //LogHelper.GetLogHelper().Debug("读取平台数据：" + patinfoStr);
                /*返回参数
                 {"Result":"0","ErrMsg":null,"ReturnData":[{"PATIENTID":"7364907","PATIENTNAME":"叶慧"}]}
                 */
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                if (result.Result)
                {
                    var list = JsonConvert.DeserializeObject<List<Tr_PatientVisitInfo>>(System.Convert.ToString(result.ReturnData));
                    result.ReturnData = list;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }
        /// <summary>
        /// 获取HIS已挂号列表
        /// </summary>
        /// <param name="stratdate">开始日期</param>
        /// <param name="enddate">截止日期</param>
        /// <param name="hospitalCode">登录院区</param>
        /// <param name="searchInfo"></param>
        /// <returns></returns>
        public CommonResult GetHisRegisterPatInfo(DateTime stratdate, DateTime enddate, string hospitalCode, string searchInfo)
        {
            

            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("GetRegisterPatInfo");
            if (GetPatInfo == null)
            {
                result.Result = false;
                result.ErrMsg = "请配置获取患者挂号信息的接口方法【GetRegisterPatInfo】";
                return result;
            }
            dynamic pat = new System.Dynamic.ExpandoObject();
            pat.StartData = stratdate.ToString("yyyy-MM-dd HH:mm:ss");
            pat.EndData = enddate.ToString("yyyy-MM-dd HH:mm:ss");
            pat.HospitalCode = hospitalCode;
            pat.SearchInfo = searchInfo;
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                if (result.Result)
                {
                    var list = JsonConvert.DeserializeObject<List<Tr_PatientVisitInfo>>(System.Convert.ToString(result.ReturnData));
                    result.ReturnData = list;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }

        public CommonResult TriageInfoToHIS(Tr_PatientVisitInfo pat)
        {
            

            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("TriageInfoToHIS");
            if (GetPatInfo == null)
            {
                result.Result = false;
                result.ErrMsg = "请配置获取患者信息回传his接口【TriageInfoToHIS】";
                return result;
            }
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }
        public CommonResult GetPatientVitalsign(Tr_PatientVisitInfo pat)
        {
            

            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("GetPatientVitalsign");
            if (GetPatInfo == null)
            {
                result.Result = false;
                result.ErrMsg = "请配置获取患者生命体征接口【GetPatientVitalsign】";
                return result;
            }
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                if (result.Result)
                {
                    var vr = JsonConvert.DeserializeObject<Tr_VitalsignRecordInfo>(System.Convert.ToString(result.ReturnData));
                    result.ReturnData = vr;
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }
        public CommonResult TriageGreenToHIS(Tr_PatientVisitInfo pat)
        {
            

            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("TriageGreenToHIS");
            if (GetPatInfo == null)
            {
                result.Result = false;
                result.ErrMsg = "请配置回传绿通接口方法【TriageGreenToHIS】";
                return result;
            }
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                return result;
            }
            catch (Exception ex)
            {
                result.Result = false;
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }
        public CommonResult SaveTriageCheck(Tr_PatientVisitInfo pat)
        {     
            var result = new CommonResult();
            var GetPatInfo = jsService.GetInterfaceToolByCode("SaveTriageCheck");
            if (GetPatInfo == null)
            {   //没有配置验证，就是不做验证
                result.Result = true;
                result.ErrMsg = "";
                return result;
            }
            var data = JsonConvert.SerializeObject(pat);
            var scriptGetPatInfo = new ScriptContent() { FunctionName = GetPatInfo.FUNCTIONNAME, JavaScriptCode = GetPatInfo.JAVASCRIPTCODE, Data = data };
            try
            {
                var patinfoStr = jsService.Convert(scriptGetPatInfo);
                result = JsonConvert.DeserializeObject<CommonResult>(patinfoStr);
                return result;
            }
            catch (Exception ex)
            {
                result.Result = true;//报错，不做验证，不要影响分诊保存
                result.ErrMsg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
                return result;
            }
        }
        public ResponseApi<CommonResult> SaveGroupInjuryInfo(Tr_GroupInjuryInfo groupInjuryInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/SaveGroupInjuryInfo", Method.POST);
                var json = JsonConvert.SerializeObject(groupInjuryInfo);
                request.AddJsonBody(json);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        public ResponseApi<CommonResult> SaveGroupInjuryUsers(Tr_GroupInjuryInfo groupInjuryInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/SaveGroupInjuryUsers", Method.POST);
                var json = JsonConvert.SerializeObject(groupInjuryInfo);
                request.AddJsonBody(json);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        public ResponseApi<CommonResult> DeleteGroupInjuryInfo(Tr_GroupInjuryInfo groupInjuryInfo)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/DeleteGroupInjuryInfo", Method.DELETE);
                var json = JsonConvert.SerializeObject(groupInjuryInfo);
                request.AddJsonBody(json);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        public ResponseApi<CommonResult> DeleteTriagePatientByPvid(string pvid)
        {
            var result = new ResponseApi<CommonResult>();
            try
            {
                #region PatientVisitInfo 基本信息
                var request = new RestRequest("api/Triage/DeleteTriagePatientByPvid", Method.DELETE);
                request.AddParameter("pvid", pvid);
                IRestResponse response = client.Execute(request);
                result = JsonConvert.DeserializeObject<ResponseApi<CommonResult>>(response.Content);
                #endregion
            }
            catch (Exception ex)
            {
                result.code = -1;
                result.msg = ex.Message;
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;
        }
        public List<PatientInfo> GetPatientInfoByPatientId(string patientid)
        {
            var result = new List<PatientInfo>();
            try
            {
                var request = new RestRequest("api/PatientInfo/GetPatientInfoByPatientId", Method.GET);
                request.AddParameter("patientid", patientid);
                IRestResponse response = client.Execute(request);
                var responseApi = JsonConvert.DeserializeObject<ResponseApi<List<PatientInfo>>>(response.Content);
                result = responseApi.data;
            }
            catch (Exception ex)
            {
                LogHelper.GetLogHelper().Error(ex);
            }
            return result;

        }
    

    }
}
